package main

import (
	"fmt"
	"math/rand"
	"time"
)

type kelvin float64

func measureTemperature(samples int, sensor func() (kelvin, int)) {
	for i := 0; i < samples; i++ {
		k, n := sensor()
		fmt.Print(n, ":")
		fmt.Printf("%vº K\n", k)
		time.Sleep(time.Second)
	}
}
func fakeSensor() (kelvin, int) {
	num := rand.Intn(151) + 150
	return kelvin(num), num
}

// 将函数传递给其它函数
func main() {
	measureTemperature(3, fakeSensor)
}
